unit Interface_SelectView;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Core_PluginsEngine;

type
  TWndSelectView = class(TForm)
    ViewList: TListBox;
    txtFileName: TEdit;
    procedure FormShow(Sender: TObject);
    procedure ViewListDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure ViewListDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    FileName : String;
  end;

var
  WndSelectView: TWndSelectView;

implementation

{$R *.dfm}

procedure TWndSelectView.FormShow(Sender: TObject);
var
  ext : String;
  i : Integer;
begin
  ext := ExtractFileExt(FileName);
  Delete(ext, 1, 1);
  txtFileName.Text := FileName;
  ViewList.Clear;

  for i := 0 to High(Plugins) do
  begin
    if @Plugins[i].ViewExt <> nil then
      if Plugins[i].ViewExt(PChar(ext)) then
      begin
        ViewList.Items.Add(IntToStr(i) + ':' + Plugins[i].Name);
      end;
  end;
end;

procedure TWndSelectView.ViewListDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Capt : String;
begin
  with ViewList.Canvas do
  begin
    FillRect(Rect);
    Capt := ViewList.Items.Strings[Index];
    Delete(Capt, 1, Pos(':', Capt));
    TextOut(Rect.Left, Rect.Top, Capt);
  end;
end;

procedure TWndSelectView.ViewListDblClick(Sender: TObject);
var
  tmps : String;
  Index : Integer;
begin
  tmps := ViewList.Items.Strings[ViewList.ItemIndex];
  tmps := Copy(ViewList.Items.Strings[ViewList.ItemIndex], 1, Pos(':', ViewList.Items.Strings[ViewList.ItemIndex])-1);
  Plugins[StrToInt(tmps)].ViewFile(PChar(FileName));
  Close;
end;

end.
